package se.sigma.selenium.testing;

import java.io.File;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.CellFormat;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;

/**
 *
 * @author eyh6112
 */
public class Excel {
    
    private File inputWorkbook;
    private Workbook w;
    protected Sheet currentSheet;
    
    public Excel(String workBook) throws Exception {
        
        this.inputWorkbook = new File(workBook);        
        this.w = Workbook.getWorkbook(inputWorkbook); 
        
        // Get the first sheet
        this.currentSheet = w.getSheet(0);
        
    }
    
    public Cell[] getRow(int row) {
        Cell[][] data = getRows(row, 1);
        return data[0];
    }
    
    public Cell[][] getRows() {
        return getRows(0, currentSheet.getRows());
    }
    
    public Cell[][] getRows(int fromWhere, int howManyRows) {
        
        // Get dynamic data about how many data columns there are
        int columns = currentSheet.getColumns() - 1;
        
        // Initialize data array
        Cell[][] data = new Cell[howManyRows][columns];
        
        // Loop over first 10 column and lines
        for (int r = 0; r < howManyRows; r++) {
            for (int c = 0; c < columns; c++) {
                data[r][c] = currentSheet.getCell(c, r + fromWhere);
            }
        }
        return data;
    }
    
    public boolean isBlank(int row, int column) {
        return isBlank(currentSheet.getCell(row, column));       
    }
    
    public boolean isBlank(Cell cell) {
        String contents = cell.getContents();
        if("".equals(contents)) {
            return true;
        } else {
            return false;
        }
    }
    
    public void writeData(int row, int column, String data) {
        
        //Label newData = Label(column, row, data, wf);
        
    
    } 
    
}